package com.study.blog.service;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.study.blog.dao.mapper.ArticleMapper;
import com.study.blog.dao.pojo.Article;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author 1
 * @data 2022/2/17
 */
@Component
public class ThreadService {

    //线程池执行增加访问量
    @Async("taskExecutor")
    public void updateArticleViewCount(ArticleMapper articleMapper, Article article) {
        int viewCounts = article.getViewCounts();
        Article updateView = new Article();
        updateView.setViewCounts(viewCounts+1);
        //使用mybatisolus
        LambdaUpdateWrapper<Article> updateWrapper = new LambdaUpdateWrapper<>();
        //设置条件id=id
        updateWrapper.eq(Article::getId,article.getId());
        updateWrapper.eq(Article::getViewCounts,article.getViewCounts());
        articleMapper.update(updateView,updateWrapper);
       /* try {
            Thread.sleep(5000);
            System.out.println("跟新完成了。。。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
    }
}
